package com.sc.nft.dto;

import cn.hutool.core.date.DateUtil;
import com.sc.nft.entity.MetaMapSettle;
import com.sc.nft.enums.MetaMapSettleSourceTypeEnum;
import com.sc.nft.enums.MetaMapSettleStatusEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Data
public class MetaMapSettleDTO {

    @ApiModelProperty(value = "订单编号")
    private String orderNo;
    @ApiModelProperty(value = "交易物名称")
    private String transName;
    @ApiModelProperty(value = "购买人id")
    private Long buyUserId;
    @ApiModelProperty(value = "来源类型")
    private MetaMapSettleSourceTypeEnum sourceType;
    @ApiModelProperty(value = "参与计算的值,他可能是钱 也可能是燃料")
    private BigDecimal participation;
    @ApiModelProperty(value = "心愿金")
    private BigDecimal wishBalancePrice;
    @ApiModelProperty(value = "订单的手续费,这个地方可以为0")
    private BigDecimal charge;
    @ApiModelProperty("模板id")
    private Long shareProfitPanelId;
    @ApiModelProperty("发送时间")
    private String sendTime;

    //下面的参数目前专门给商城用的
    @ApiModelProperty("省")
    private String province;
    @ApiModelProperty("市")
    private String city;
    @ApiModelProperty("区")
    private String area;


    /**
     * 拒绝分钱.
     *
     * @return MetaMapSettle
     */
    public MetaMapSettle turnDown(String describe) {
        MetaMapSettle metaMapSettle = new MetaMapSettle();
        metaMapSettle.setOrderNo(this.orderNo);
        metaMapSettle.setBuyUserId(this.buyUserId);
        metaMapSettle.setEarningsUserId(0L);
        metaMapSettle.setTransName(this.transName);
        metaMapSettle.setSourceType(this.sourceType);
        metaMapSettle.setStatus(MetaMapSettleStatusEnum.REFUSED);
        metaMapSettle.setDescribeContent(describe);
        metaMapSettle.setParticipation(this.getParticipation());
        metaMapSettle.setCharge(this.getCharge());
        metaMapSettle.setDivide(BigDecimal.ZERO);
        metaMapSettle.setQuota(BigDecimal.ZERO);
        metaMapSettle.setVersion(0);
        metaMapSettle.setGetTime(DateUtil.date());
        return metaMapSettle;
    }


    /**
     * 前置验证通过
     *
     * @return MetaMapSettle
     */
    public MetaMapSettle turnDownPass() {
        MetaMapSettle metaMapSettle = new MetaMapSettle();
        metaMapSettle.setOrderNo(this.orderNo);
        metaMapSettle.setBuyUserId(this.buyUserId);
        StringBuilder metaMap = new StringBuilder();
        if (StringUtils.isNotBlank(province)) {
            metaMap.append(province);
        }
        if (StringUtils.isNotBlank(city)) {
            metaMap.append(city);
        }
        if (StringUtils.isNotBlank(area)) {
            metaMap.append(area);
        }
        metaMapSettle.setMetaMap(metaMap.toString());
        metaMapSettle.setTransName(transName);
        metaMapSettle.setEarningsUserId(0L);
        metaMapSettle.setSourceType(this.sourceType);
        metaMapSettle.setStatus(MetaMapSettleStatusEnum.TO_BE_PROCESSED);
        metaMapSettle.setParticipation(this.getParticipation());
        metaMapSettle.setCharge(this.getCharge());
        metaMapSettle.setDivide(BigDecimal.ZERO);
        metaMapSettle.setVersion(0);
        metaMapSettle.setQuota(BigDecimal.ZERO);
        return metaMapSettle;
    }

    /**
     * 发送订单的消费
     * @param orderNo
     * @param buyUserId
     * @param sourceType
     * @param participation
     * @param charge
     * @param shareProfitPanelId
     * @return
     */
    public MetaMapSettleDTO order(String orderNo, Long buyUserId, MetaMapSettleSourceTypeEnum sourceType, BigDecimal participation, BigDecimal charge, String transName, Long shareProfitPanelId, String date) {
        MetaMapSettleDTO metaMapSettleDTO = new MetaMapSettleDTO();
        metaMapSettleDTO.setTransName(transName);
        metaMapSettleDTO.setOrderNo(orderNo);
        metaMapSettleDTO.setBuyUserId(buyUserId);
        metaMapSettleDTO.setSourceType(sourceType);
        metaMapSettleDTO.setSendTime(date);
        metaMapSettleDTO.setParticipation(participation);
        metaMapSettleDTO.setCharge(charge);
        metaMapSettleDTO.setShareProfitPanelId(shareProfitPanelId);
        return metaMapSettleDTO;
    }

    /**
     * 商城订单的消费
     * @param orderNo
     * @param buyUserId
     * @param sourceType
     * @param participation
     * @param charge
     * @param shareProfitPanelId
     * @param province
     * @param city
     * @param area
     * @return
     */
    public MetaMapSettleDTO mall(String orderNo, String transName, Long buyUserId, MetaMapSettleSourceTypeEnum sourceType, BigDecimal participation, BigDecimal charge, Long shareProfitPanelId, String province, String city, String area) {
        MetaMapSettleDTO metaMapSettleDTO = new MetaMapSettleDTO();
        metaMapSettleDTO.setOrderNo(orderNo);
        metaMapSettleDTO.setBuyUserId(buyUserId);
        metaMapSettleDTO.setSourceType(sourceType);
        metaMapSettleDTO.setParticipation(participation);
        metaMapSettleDTO.setCharge(charge);
        metaMapSettleDTO.setShareProfitPanelId(shareProfitPanelId);
        metaMapSettleDTO.setProvince(province);
        metaMapSettleDTO.setSendTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        metaMapSettleDTO.setCity(city);
        metaMapSettleDTO.setTransName(transName);
        metaMapSettleDTO.setArea(area);
        metaMapSettleDTO.setWishBalancePrice(wishBalancePrice);
        return metaMapSettleDTO;
    }
}
